﻿package Framework.Util
{

    public class IDMap extends Object
    {
        private var _messagId:int;
        private var _object:Object;

        public function IDMap()
        {
            this._object = new Object();
            this._messagId = 0;
        }

        public function insert(obj:Object) : int
        {
            var item:String = null;
            var messagId:int = 1;
            for (item in this._object)
            {
                
                if (messagId <= int(item))
                {
					messagId = int(item) + 1;
                }
            }
            this._messagId = messagId;
            this._object[this._messagId] = obj;
            return this._messagId;
        }

        public function remove(key:int) : Boolean
        {
            if (this._object[key] == undefined)
            {
                return false;
            }
            delete this._object[key];
            return true;
        }

        public function findAndRemove(messageId:int) : Object
        {
            if (this._object[messageId] == undefined)
            {
                return null;
            }
            var data:* = this._object[messageId];
            delete this._object[messageId];
            return data;
        }
    }
}
